﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Text.RegularExpressions;

/***********************************************************
* Description: SQL CLR
* Date:   2013-08-14 13:39
* Author: 刘俊
*
*    Created By: 刘俊
*  Created Date: 2013-08-14
*      Comments: 创建正则表达式匹配字符串函数。有匹配，返回true；无匹配，返回false
************************************************************
*  __                        _____                     
* /\ \       __             /\___ \                    
* \ \ \     /\_\  __  __    \/__/\ \  __  __    ___    
*  \ \ \  __\/\ \/\ \/\ \      _\ \ \/\ \/\ \ /' _ `\  
*   \ \ \LJ \\ \ \ \ \_\ \    /\ \_\ \ \ \_\ \/\ \/\ \ 
*    \ \____/ \ \_\ \____/    \ \____/\ \____/\ \_\ \_\
*     \/___/   \/_/\/___/      \/___/  \/___/  \/_/\/_/
************************************************************/

public partial class UserDefinedFunctions
{
    [Microsoft.SqlServer.Server.SqlFunction]
    public static System.Data.SqlTypes.SqlBoolean Regexp_Like(string source,string regex)
    {
        Match match = Regex.Match(source, regex);
        if (match.Success)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
};

